package SocketProgram;

import java.io.*;
import java.net.*;

class SocketClient{
	Socket socket = null;
	BufferedReader br = null;
	BufferedWriter bw = null;
	String ip;
	int port;
	String result;

	public SocketClient(){
		ip = "127.0.0.1";
		port = 8125;	
	}
	
	public SocketClient(String ip, int port) {
		this.ip = ip;
		this.port = port;
	}
	
	public void connectC() throws IOException {
		try{
			socket = new Socket(ip, port);
			} catch (IOException e) { 
				throw e;
			}
	}
	
	public void request(String input) throws IOException {
		try{
			br = new BufferedReader(new InputStreamReader( socket.getInputStream() ) );
			bw = new BufferedWriter(new OutputStreamWriter( socket.getOutputStream() ) );
			
			String packet = input;
			bw.write(packet);
			bw.newLine();
			bw.flush();
			
			result = br.readLine();
		    } catch (IOException e) { 
				throw e;
			}
	}
	public void socket_close() throws IOException {
		try {
			br.close();
			bw.close();
			socket.close();
		} catch (IOException e) {
			throw e;
		}
	}
}